Skip to main content

LinkController

The LinkController manages SWMM network links (conduits, channels, etc.) and provides access to link data, attributes, and simulation results.

Overview

This controller handles all link-related operations including retrieving link definitions, time series data, aggregated values, and simulation results. It integrates with multiple Azure storage services to provide comprehensive link information.

Data Sources

  • Azure Blob Storage:
    • networkmodel container for link definitions
    • swmm-output container for simulation results
  • Azure Table Storage:
    • Runs table for run metadata
    • LinkOutput table for link time series data
  • Configuration: appsettings.json for connection string

Endpoints

Retrieves all network links with their properties and geographic coordinates.

Response:

  • 200 OK: Returns JSON string containing link definitions
  • 500 Internal Server Error: Storage or processing error

Data Flow:

Link Data Structure:

{
"linkId": {
"id": "link_name",
"type": "CONDUIT",
"fromNode": "node1",
"toNode": "node2",
"fromLatitude": "lat1",
"fromLongitude": "lon1",
"toLatitude": "lat2",
"toLongitude": "lon2"
}
}

GET /api/link/values

Retrieves time series data for a specific link attribute.

Query Parameters:

  • index (string): Link index
  • runDateTime (string): Simulation run datetime
  • measurementIndex (string): Attribute type (flow, depth, etc.)
  • scenario (string): Scenario name

Response:

  • 200 OK: Returns time series as JSON array [[timestamp, value], ...]
  • 404 Not Found: Link or run not found
  • 500 Internal Server Error: Processing error

Data Flow:

GET /api/link/aggregatedvalues

Retrieves aggregated time series data across multiple links.

Query Parameters:

  • linkIndexes (string): Comma-separated link indices
  • runDateTime (string): Simulation run datetime
  • measurementIndex (string): Attribute type
  • scenario (string): Scenario name

Response:

  • 200 OK: Returns aggregated values array
  • 404 Not Found: Run not found
  • 500 Internal Server Error: Processing error

Data Flow:

GET /api/link/results

Retrieves simulation results for a specific link at a given timestep.

Query Parameters:

  • step (string): Simulation timestep
  • runDateTime (string): Simulation run datetime
  • linkIndex (string): Link index

Response:

  • 200 OK: Returns SwmmLinkResult object
  • 404 Not Found: Results not found
  • 500 Internal Server Error: Processing error

Data Flow:

Azure Storage Details

Blob Containers

  • networkmodel: Contains link and node definitions
  • swmm-output: Contains simulation results by timestep

Table Storage

  • Runs: Run metadata and parameters
  • LinkOutput: Link time series data
  • Errors: Error logging

Blob Structure

networkmodel/
├── {partitionKey}/
│ ├── links
│ └── nodes

swmm-output/
├── {partitionKey}_{scenario}_{datetime}/
│ ├── {step}
│ └── ...

Data Models

public class LinkDefinition
{
public string Id { get; set; }
public string Type { get; set; }
public string FromNode { get; set; }
public string ToNode { get; set; }
public double FromLatitude { get; set; }
public double FromLongitude { get; set; }
public double ToLatitude { get; set; }
public double ToLongitude { get; set; }
}

Time Series Point

public class TimeSeriesPoint
{
public long Timestamp { get; set; } // Unix milliseconds
public double? Value { get; set; }
}

Configuration

Required Settings:

{
"Values": {
"CloudStorageConnectionString": "DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...;EndpointSuffix=core.windows.net"
}
}

Error Handling

  • Storage Errors: Logged to Azure Table Storage
  • Missing Data: Returns null or empty arrays
  • Invalid Parameters: Graceful parameter validation
  • Time Processing: Handles timezone and format issues

Performance Considerations

  • Memory Management: Uses memory streams for blob operations
  • Data Parsing: Efficient string parsing for large datasets
  • Caching: No built-in caching (consider for frequently accessed data)
  • Batch Operations: Supports multiple link aggregation

Dependencies

  • Azure.Storage.Blobs
  • Azure.Data.Tables
  • GqcStorage1 (Storage utilities)
  • SwmmUtilities (Time series processing)
  • SwmmModels (Data models)
  • CONDUIT: Standard pipe/conduit
  • CHANNEL: Open channel
  • ORIFICE: Orifice structure
  • WEIR: Weir structure
  • PUMP: Pump station

Time Series Processing

  • Unix Timestamps: Converts to milliseconds since epoch
  • Time Steps: Uses reporting time step from run configuration
  • Time Windows: Supports start/end time filtering
  • Data Aggregation: Sums values across multiple links